package com.java110.mall.goods.bmo.housekeepingServ.impl;

import com.java110.core.annotation.Java110Transactional;
import com.java110.dto.file.FileRelDto;
import com.java110.mall.goods.bmo.housekeepingServ.IDeleteHousekeepingServBMO;
import com.java110.intf.system.IFileInnerServiceSMO;
import com.java110.intf.system.IFileRelInnerServiceSMO;
import com.java110.intf.goods.IHousekeepingServInnerServiceSMO;
import com.java110.intf.goods.IProductDetailInnerServiceSMO;
import com.java110.intf.goods.IProductServKeywordInnerServiceSMO;
import com.java110.po.file.FileRelPo;
import com.java110.po.housekeeping.HousekeepingServPo;
import com.java110.po.product.ProductDetailPo;
import com.java110.po.product.ProductServKeywordPo;
import com.java110.vo.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;


@Service("deleteHousekeepingServBMOImpl")
public class DeleteHousekeepingServBMOImpl implements IDeleteHousekeepingServBMO {

    @Autowired
    private IHousekeepingServInnerServiceSMO housekeepingServInnerServiceSMOImpl;
    @Autowired
    private IProductDetailInnerServiceSMO productDetailInnerServiceSMOImpl;
    @Autowired
    private IFileInnerServiceSMO fileInnerServiceSMOImpl;
    @Autowired
    private IFileRelInnerServiceSMO fileRelInnerServiceSMOImpl;
    @Autowired
    private IProductServKeywordInnerServiceSMO productServKeywordInnerServiceSMOImpl;
    /**
     * @param housekeepingServPo 数据
     * @return 订单服务能够接受的报文
     */
    @Java110Transactional
    public ResponseEntity<String> delete(HousekeepingServPo housekeepingServPo, ProductDetailPo productDetailPo) {

        int flag = housekeepingServInnerServiceSMOImpl.deleteHousekeepingServ(housekeepingServPo);

        if (flag < 1) {
        return ResultVo.createResponseEntity(ResultVo.CODE_ERROR, "删除失败");
        }
        //删除服务详情
        productDetailPo.setProductId(housekeepingServPo.getServId());
        productDetailInnerServiceSMOImpl.deleteProductDetail(productDetailPo);
        //删除图片
        doDeleteRentingFile(housekeepingServPo,FileRelDto.REL_TYPE_CD_GOODS_COVER);
        //删除轮播图
        doDeleteRentingFile(housekeepingServPo,FileRelDto.REL_TYPE_CD_GOODS_CAROUSEL_FIGURE);
        //删除关键字
        doDeletekeywords(housekeepingServPo);
        return ResultVo.createResponseEntity(ResultVo.CODE_OK, "删除成功");
    }
    /**
     * 保存房屋租赁 图片
     *
     */
    private void doDeletekeywords(HousekeepingServPo housekeepingServPo) {

            ProductServKeywordPo servKeywordPo = new ProductServKeywordPo();
            servKeywordPo.setObjId( housekeepingServPo.getServId() );
            servKeywordPo.setShopId( housekeepingServPo.getShopId() );
           int save = productServKeywordInnerServiceSMOImpl.deleteProductServKeyword( servKeywordPo );
            if (save < 1) {
                throw new IllegalArgumentException("关键字删除失败");
            }
    }
    /**
     * 保存房屋租赁 图片
     *
     * @param housekeepingServPo
     */
    private void doDeleteRentingFile(HousekeepingServPo housekeepingServPo, String fileTypeCd) {


        FileRelPo fileRelPo = new FileRelPo();
        fileRelPo.setObjId(housekeepingServPo.getServId());
        fileRelPo.setRelTypeCd(fileTypeCd);
        fileRelInnerServiceSMOImpl.deleteFileRel(fileRelPo);
    }

}
